package pl.org.lutra.planner.gui.table;

import java.awt.Color;

import javax.swing.JTable;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;

import pl.org.lutra.planner.model.data.Segment;

public class PlannerTable<T extends Segment> extends JTable {
	private static final long serialVersionUID = -872426514666733474L;

	public PlannerTable(PlannerTableModel<T> model) {
		super(model);

		setColumnSelectionAllowed(false);
		setCellSelectionEnabled(false);
	}

	@Override
	public Color getForeground() {
		return isEnabled() ? Color.BLACK : Color.LIGHT_GRAY;
	}

	protected void setColumnBehavior(PlannerColumn<T> column, TableCellRenderer renderer, TableCellEditor editor) {
		int columnIndex = getColumnModel().getColumnIndex(column.getLabel());
		TableColumn tableColumn = getColumnModel().getColumn(columnIndex);

		if (renderer != null) {
			tableColumn.setCellRenderer(renderer);
		}
		if (editor != null) {
			tableColumn.setCellEditor(editor);
		}
	}
}
